package demo1;

import java.math.RoundingMode;
import java.util.Arrays;
import java.util.Random;
import java.util.Scanner;

/**
 * @Author liangzai
 * @Description:
 */
public class Training {

    //食堂 （蓝桥杯）
    public static void main1(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int q = scanner.nextInt();
        while (q-- > 0) {
            int a2 = scanner.nextInt() * 2;
            int a3 = scanner.nextInt() * 3;
            int a4 = scanner.nextInt() * 4;
            int b4 = scanner.nextInt();
            int b6 = scanner.nextInt();
            int ret = a2 + a3 + a4;
            while (b6 > 0) {
                if (b6 >= 1 && a3 >= 6) {
                    b6--;
                    a3 -= 6;
                    continue;
                } else if (b6 >= 1 && a2 >= 6) {
                    a2 -= 6;
                    b6--;
                    continue;
                } else if (b6 > 0 && a4 >= 4) {
                    b6--;
                    a4 -= 4;
                    continue;
                } else if (b6 > 0 && a3 >= 3) {
                    b6--;
                    a3 -= 3;
                    continue;
                } else if (b6 > 0 && a2 >= 2) {
                    b6--;
                }
                break;
            }
            while (b4 > 0) {
                if (b4 >= 4 && a4 >= 4) {
                    a4 -= 4;
                    b4 -= 4;
                    continue;
                } else if (b4 >= 2 && a2 >= 2) {
                    b4 -= 2;
                    a2 -= 2;
                    continue;
                } else if (a2 == 0 && a4 == 0 && b4 >= 3 && a3 >= 3) {
                    b4 -= 3;
                    a3 -= 3;
                    continue;
                }
                break;
            }
            ret = ret - a2 - a3 - a4;
            System.out.println(ret);
        }
    }

    //翻转对
    int ret = 0;
    int[] tmp;
    public int reversePairs(int[] nums) {
        tmp = new int[nums.length];
        mergeSort(nums, 0, nums.length - 1);
        return ret;
    }

    private void mergeSort(int[] nums, int left, int right) {
        if (left >= right) return;
        int mid = (left + right) / 2;
        mergeSort(nums, left, mid);
        mergeSort(nums, mid + 1, right);

        int pcur1 = left;
        int pcur2 = mid + 1;
        int i = left;
        int k = 0;
        while (pcur2 <= right) {
            while (pcur1 <= mid && (nums[pcur1] / 2.0) <= nums[pcur2]) {
                pcur1++;
            }
            if (pcur1 > mid) break;
            ret += mid - pcur1 + 1;
            pcur2++;
        }

        pcur1 = left;
        pcur2 = mid + 1;
        while (pcur1 <= mid && pcur2 <= right) {
//            if (nums[pcur1] > nums[pcur2] * 2) {
//                ret += mid-pcur1+1;
            if (nums[pcur1] > nums[pcur2]) {
                tmp[k++] = nums[pcur2++];
                //ret += mid-pcur1+1;
            } else {
                tmp[k++] = nums[pcur1++];
                //ret += mid-pcur1+2;
            }
//            }else {
//                if(nums[pcur1]>nums[pcur2]) tmp[k++] = nums[pcur2++];
//                else tmp[k++] = nums[pcur1++];
//            }
        }

        while (pcur1 <= mid) {
            tmp[k++] = nums[pcur1++];
        }
        while (pcur2 <= right) {
            tmp[k++] = nums[pcur2++];
        }
        for (int j = left; j <= right; j++) {
            nums[j] = tmp[j - left];
        }
    }

    public static void main2(String[] args) {
        String name1 = "luoqian";
        String name2 = "liuzhi";
        Random random = new Random();
        int ran = random.nextInt(2);
        if (ran == 1) {
            System.out.println(name1 + "♥" + name2);
        } else System.out.println(name1 + "讨厌" + name2);
    }
}













